# 2024/4/17 上午10:03 HFL
import requests
import hashlib

# 发送生成验证码接口请求，获取响应数据
base_url = 'http://kdtx-test.itheima.net'
url_verify = base_url+'/api/captchaImage'
verify_code = requests.get(url=url_verify)
# 定义一个变量，用来接收uuid,提取uuid变量
uuid = verify_code.json()['uuid']
# url路径前面的公共部分采用变量进行拼接
url_login = base_url + '/api/login'
data = {
    "username": "admin",
    "password": "HM_2023_test",
    "code": "2",
    "uuid": uuid
}
resp_login = requests.post(url=url_login,json=data)
token = resp_login.json()['token']

headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer"+" " + token
}
json = {
    "name": "小张的课程",
    "subject": 6,
    "price": 200,
    "applicablePerson": 3
}
url_course = base_url+'/api/clues/course'
resp_add_course = requests.post(url=url_course,json=json,headers=headers)
print(resp_add_course.json())

print(resp_add_course.status_code)

